package com.lrkj.payfee.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.payfee.domain.ChargeItem;
import com.lrkj.payfee.service.IChargeItemService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 收费项目Controller
 *
 * @author yajun_ren
 * @date 2021-07-26
 */
@RestController
@RequestMapping("/payfee/item")
@Api(tags ="收费项目")
public class ChargeItemController extends BaseController
{
    @Autowired
    private IChargeItemService chargeItemService;

    /**
     * 查询收费项目列表
     */
    @ApiOperation(value = "查询收费项目列表", notes = "查询收费项目列表")
    @GetMapping("/list")
    public TableDataInfo list(ChargeItem chargeItem)
    {
        startPage();
        List<ChargeItem> list = chargeItemService.selectChargeItemList(chargeItem);
        return getDataTable(list);
    }

    /**
     * 导出收费项目列表
     */
	@ApiOperation(value = "导出收费项目列表", notes = "导出收费项目列表")
    @PreAuthorize("@ss.hasPermi('payfee:item:export')")
    @Log(title = "收费项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChargeItem chargeItem)
    {
        List<ChargeItem> list = chargeItemService.selectChargeItemList(chargeItem);
        ExcelUtil<ChargeItem> util = new ExcelUtil<ChargeItem>(ChargeItem.class);
        return util.exportExcel(list, "收费项目数据");
    }

    /**
     * 获取收费项目详细信息
     */
	@ApiOperation(value = "获取收费项目详细信息", notes = "获取收费项目详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:item:query')")
    @GetMapping(value = "/{chargeId}")
    public AjaxResult getInfo(@PathVariable("chargeId") String chargeId)
    {
        return AjaxResult.success(chargeItemService.selectChargeItemById(chargeId));
    }

    /**
     * 新增收费项目
     */
	  @ApiOperation(value = "新增收费项目", notes = "新增收费项目")
    @PreAuthorize("@ss.hasPermi('payfee:item:add')")
    @Log(title = "收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeItem chargeItem)
    {
        return toAjax(chargeItemService.insertChargeItem(chargeItem));
    }

    /**
     * 修改收费项目
     */
	 @ApiOperation(value = "修改收费项目", notes = "修改收费项目")
    @PreAuthorize("@ss.hasPermi('payfee:item:edit')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeItem chargeItem)
    {
        return toAjax(chargeItemService.updateChargeItem(chargeItem));
    }

    /**
     * 删除收费项目
     */
	 @ApiOperation(value = "删除收费项目", notes = "删除收费项目")
    @PreAuthorize("@ss.hasPermi('payfee:item:remove')")
    @Log(title = "收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargeIds}")
    public AjaxResult remove(@PathVariable String[] chargeIds)
    {
        return toAjax(chargeItemService.deleteChargeItemByIds(chargeIds));
    }
}
